Crate tower_cookies
source ·Expand description
A cookie manager middleware built on top of tower.
Example
With axum:
use axum::{routing::get, Router};
use std::net::SocketAddr;
use tower_cookies::{Cookie, CookieManagerLayer, Cookies};
#[tokio::main]
async fn main() {
let app = Router::new()
.route("/", get(handler))
.layer(CookieManagerLayer::new());
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
axum::Server::bind(&addr)
.serve(app.into_make_service())
.await
.unwrap();
}
async fn handler(cookies: Cookies) -> &'static str {
cookies.add(Cookie::new("hello_world", "hello_world"));
"Check your cookies."
}
A complete CRUD cookie example in examples/counter.rs
Modules
Structs
Representation of an HTTP cookie.
Middleware to use
Cookies
.Layer to apply
CookieManager
middleware.A parsed on-demand cookie jar.
A cryptographic master key for use with
Signed
and/or Private
jars.A cookie jar that provides authenticated encryption for its cookies.
A child cookie jar that authenticates its cookies.
It signs all the cookies added to it and verifies cookies retrieved from it.
Any cookies stored in
SignedCookies
are provided integrity and authenticity. In other
words, clients cannot tamper with the contents of a cookie nor can they fabricate cookie
values, but the data is visible in plaintext.